package com.appkubes.mall.admin.application.order.order.dao;

import com.appkubes.mall.admin.application.order.order.entity.model.CollectRecordsResult;
import com.appkubes.mall.core.pojo.MallCollectedRecordsMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CollectRecordsDao extends MallCollectedRecordsMapper {
    @Select({"<script>",
            "SELECT " +
                    "<choose><when test='isTotal!=true'>" +
                    " a.*, b.store_name " +
                    "</when>" +
                    "<otherwise>" +
                    " count(`a`.collected_records_key) as total" +
                    "</otherwise></choose>" +
                    " FROM `mall_collected_records` a " +
                    " INNER JOIN mall_sassadmin_store_info b ON a.app_key=b.app_key " +
                    " WHERE 1=1 ${queryStr} " +
                    " ORDER BY a.id DESC " +
                    "<when test='isTotal!=true'>" +
                    "LIMIT #{page},#{limit}" +
                    "</when>",
            "</script>"})
    List<CollectRecordsResult> getList(@Param("queryStr") String queryStr,
                                       @Param("page") int page,
                                       @Param("limit") int limit,
                                       @Param("isTotal") boolean isTotal);

    @Update({"<script>",
            "update mall_leader set verify_man=#{verifyMan},verify_time=#{nowTime},check_state=#{state} where id in ",
            "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'> #{id} </foreach> " ,
            "</script>"})
    int verify(@Param("ids") String[] ids, @Param("nowTime") int nowTime, @Param("state") int state,@Param("verifyMan") int verifyMan);
}
